<?php
define("FILE_DIR", realpath(dirname(__FILE__) . "/../../.."));

if (!defined('DIRECTORY_SEPARATOR')) {
    if (OS_WINDOWS) {
        define('DIRECTORY_SEPARATOR', "\\");
    } else {
        define('DIRECTORY_SEPARATOR', "/");
    }
}

include_once FILE_DIR . DIRECTORY_SEPARATOR . 'application' . DIRECTORY_SEPARATOR . 'app_config.php';
include_once FILE_DIR . DIRECTORY_SEPARATOR . 'application' . DIRECTORY_SEPARATOR . 'app_constant.php';
include_once FILE_DIR . DIRECTORY_SEPARATOR . 'application' . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'functions.php';
include_once FILE_DIR . DIRECTORY_SEPARATOR . 'application' . DIRECTORY_SEPARATOR .'language' . DIRECTORY_SEPARATOR .'en' . DIRECTORY_SEPARATOR . 'common.php';
include_once FILE_DIR . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR .'mail.php';
include_once FILE_DIR . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . 'external' . DIRECTORY_SEPARATOR .'Smarty' . DIRECTORY_SEPARATOR .'libs' . DIRECTORY_SEPARATOR .'Smarty.class.php';
include_once FILE_DIR . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR .'DRX_StringUtils.php';

function loadConstants() {
    $connection = @mysql_connect(DATABASE_MAIN_SERVER, DATABASE_MAIN_LOGIN, DATABASE_MAIN_PASSWORD);
    if (!$connection) {
        if (DEBUG_MODE == 1) {
            error_log('Could not connect: ' . mysql_error() . '\n', 3, LOG_FILE);
        }
        die('Could not connect: ' . mysql_error());
    }

    $db = @mysql_select_db(DATABASE_MAIN_NAME, $connection);

    if (!$db) {
        if (DEBUG_MODE == 1) {
            error_log('Could not select dabatase: ' . mysql_error() . '\r\n', 3, LOG_FILE);
        }
        die('Could not select dabatase: ' . mysql_error());
    }

    $sql = "SELECT * FROM PARAMETER";
    $result = @mysql_query($sql, $connection);

    if (!$result && DEBUG_MODE == 1) {
        error_log('Cannot load constant. ' . mysql_error() . '\r\r\n', 3, LOG_FILE);
        exit();
    }
    while ($row = mysql_fetch_assoc($result)) {
        if (!defined($row["NOM"])) {
            define($row["NOM"], $row["VALUE"]);
        }
    }
}